#include <sys/types.h>
#include <unistd.h>
#include <signal.h>
#include <cassert>
#include <functional>
#include <iostream>
#include "./../../source/server.hpp"

int main()
{
    signal(SIGCHLD, SIG_IGN);
    for (int i = 0; i < 10; ++i)
    {
        pid_t pid = fork();
        if (pid < 0) {
            std::cerr << "fork err" << std::endl;
            abort();
        }
        else if (pid == 0) {
            Socket cli;
            cli.ClinetCreate("127.0.0.1", 8889);
            std::string req;
            req += "GET /Get HTTP/1.1\r\n";
            req += "Connection: keep-alive\r\n";
            req += "\r\n";
            while (true)
            {
                assert(cli.Send(req.c_str(), req.size()) != -1);
                char buff[1024] = { 0 };
                ssize_t n = cli.Recv(buff, 1023);
                assert(n != -1);
                buff[n] = 0;
                std::cout << "[" << buff << "]" << std::endl;
            }
            exit(1);
        } else {}
    }
    while (true) { sleep(1); }
    return 0;
}